package com.framework.boc.admin.security.controller;

import com.framework.boc.admin.security.models.AuthenticationRequestBody;
import com.framework.boc.admin.security.models.AuthenticationResponseBody;
import com.framework.boc.admin.sms.SmsCode;
import com.framework.boc.admin.sms.SmsCodeGenerator;
import com.framework.boc.admin.sms.SmsCodeSender;
import com.framework.boc.controller.BaseController;
import com.framework.boc.error.CommonException;
import com.framework.boc.response.CommonResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
public class AuthenticateController extends BaseController {

    @Autowired
    SmsCodeGenerator smsCodeGenerator;

    @Autowired
    SmsCodeSender smsCodeSender;

    @Autowired
    HttpServletRequest httpServletRequest;


    @GetMapping("/require-login")
    public CommonResponse requireLogin() {
        return CommonResponse.error(401, "请登录系统");
    }

    @GetMapping("/sms/code")
    public CommonResponse requireSmsCode(@RequestParam("phoneNum") String phoneNum) {
        SmsCode code = smsCodeGenerator.generate(phoneNum);
        smsCodeSender.send(code);
        httpServletRequest.getSession().setAttribute(phoneNum, code);
        return CommonResponse.success("验证码发送成功");
    }



}
